package com.project.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.RoleBean;
import com.project.mapper.IRoleMapper;
import com.project.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RoleServiceImpl implements IRoleService {

    @Autowired
    private IRoleMapper mapper;
    @Override
    public IPage<RoleBean> cutAll(int pageNo) {
        return mapper.selectPage(new Page<RoleBean>(pageNo,PAGSIZE),null);
    }

    @Override
    public List<RoleBean> findAll() {
        return mapper.selectList(null);
    }

    @Override
    public void add(RoleBean role, int[] gradeArray) {
        mapper.insert(role);
        mapper.addGradeList(role.getId(),gradeArray);
    }

    @Override
    public RoleBean findById(int roleId) {
        RoleBean role = mapper.selectById(roleId);
        role.setGradeList(mapper.findByRoleId(roleId));
        return role;
    }

    @Override
    public void update(int roleId, int[] gradeArray) {
        mapper.updateGrade(roleId,gradeArray);
    }

    @Override
    public void del(int roleId) {
        mapper.del(roleId);
    }
}
